package com.rbac.web.impl;

import com.rbac.web.db.UserRoleDAO;
import com.rbac.web.db.UserRoleDO;
import com.rbac.web.model.UserRole;
import com.rbac.web.service.IUserRoleService;
import java.util.Optional;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

/**
 * @author gengaoliu
 */
@Service
@RequiredArgsConstructor
public class UserRoleServiceImpl implements IUserRoleService {
  final UserRoleDAO dao;

  @Override
  public void insert(UserRole userRole) {
    dao.insert(UserRoleDO.from(userRole));
  }

  @Override
  public Optional<UserRole> findByUserId(Integer userId) {
    return Optional.of(dao.findByUserId(userId)).map(UserRoleDO::to);
  }
}
